<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>有效字母异位词 - 算法详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-header {
            background: #2d2d2d;
            padding: 12px 20px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .code-dots {
            display: flex;
            gap: 8px;
        }
        .dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .dot-red { background: #ff5f56; }
        .dot-yellow { background: #ffbd2e; }
        .dot-green { background: #27c93f; }
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
        }
        code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            color: #e6e6e6;
            line-height: 1.6;
        }
        .keyword { color: #c678dd; }
        .function { color: #61afef; }
        .string { color: #98c379; }
        .number { color: #d19a66; }
        .comment { color: #5c6370; }
        .operator { color: #56b6c2; }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .floating-icon {
            animation: float 3s ease-in-out infinite;
        }
        @keyframes float {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto">
            <div class="text-center">
                <div class="mb-6">
                    <i class="fas fa-code text-6xl floating-icon opacity-80"></i>
                </div>
                <h1 class="text-5xl md:text-6xl font-bold mb-4 serif-font">有效字母异位词</h1>
                <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto">
                    探索字符串处理的优雅之道，掌握哈希表与排序的精妙应用
                </p>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-12">
        <!-- Problem Description Card -->
        <div class="bg-white rounded-2xl shadow-lg p-8 mb-8 card-hover">
            <div class="flex items-center mb-6">
                <i class="fas fa-book-open text-3xl text-purple-600 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">题目描述</h2>
            </div>
            <p class="text-lg text-gray-700 leading-relaxed">
                <span class="drop-cap serif-font">给</span>定两个字符串 s 和 t，判断它们是否是字母异位词。字母异位词指字母相同但排列不同的字符串。这道题目看似简单，却蕴含着算法设计的智慧，是理解哈希表应用的绝佳案例。
            </p>
        </div>

        <!-- Core Concepts Grid -->
        <div class="grid md:grid-cols-2 gap-6 mb-12">
            <div class="bg-gradient-to-br from-purple-50 to-pink-50 rounded-2xl p-6 card-hover">
                <div class="flex items-center mb-4">
                    <i class="fas fa-brain text-2xl text-purple-600 mr-3"></i>
                    <h3 class="text-xl font-bold text-gray-800">核心考点</h3>
                </div>
                <div class="flex flex-wrap gap-3">
                    <span class="px-4 py-2 bg-white rounded-full text-purple-700 font-medium shadow-sm">
                        <i class="fas fa-hashtag mr-1"></i> 哈希表
                    </span>
                    <span class="px-4 py-2 bg-white rounded-full text-pink-700 font-medium shadow-sm">
                        <i class="fas fa-sort mr-1"></i> 排序算法
                    </span>
                </div>
            </div>

            <div class="bg-gradient-to-br from-blue-50 to-indigo-50 rounded-2xl p-6 card-hover">
                <div class="flex items-center mb-4">
                    <i class="fas fa-clock text-2xl text-blue-600 mr-3"></i>
                    <h3 class="text-xl font-bold text-gray-800">复杂度分析</h3>
                </div>
                <div class="space-y-2">
                    <p class="text-gray-700">
                        <i class="fas fa-hourglass-half text-blue-500 mr-2"></i>
                        <span class="font-medium">时间复杂度：</span>O(n)
                    </p>
                    <p class="text-gray-700">
                        <i class="fas fa-memory text-indigo-500 mr-2"></i>
                        <span class="font-medium">空间复杂度：</span>O(1)
                    </p>
                </div>
            </div>
        </div>

        <!-- Solution Approach -->
        <div class="bg-white rounded-2xl shadow-lg p-8 mb-8">
            <div class="flex items-center mb-6">
                <i class="fas fa-lightbulb text-3xl text-yellow-500 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">解题思路</h2>
            </div>
            
            <div class="space-y-6">
                <div class="flex items-start">
                    <div class="flex-shrink-0 w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center mr-4">
                        <span class="text-purple-700 font-bold">1</span>
                    </div>
                    <div>
                        <h4 class="text-lg font-semibold text-gray-800 mb-2">长度检查</h4>
                        <p class="text-gray-700">首先判断两个字符串的长度是否相等，若不相等则必定不是异位词。</p>
                    </div>
                </div>

                <div class="flex items-start">
                    <div class="flex-shrink-0 w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center mr-4">
                        <span class="text-purple-700 font-bold">2</span>
                    </div>
                    <div>
                        <h4 class="text-lg font-semibold text-gray-800 mb-2">字符频率统计</h4>
                        <p class="text-gray-700">使用数组记录每个字符出现的频率差值，遍历两个字符串，对应位置的字符分别增减计数。</p>
                    </div>
                </div>

                <div class="flex items-start">
                    <div class="flex-shrink-0 w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center mr-4">
                        <span class="text-purple-700 font-bold">3</span>
                    </div>
                    <div>
                        <h4 class="text-lg font-semibold text-gray-800 mb-2">结果验证</h4>
                        <p class="text-gray-700">检查计数数组是否全为零，若是则两个字符串互为异位词。</p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Algorithm Visualization -->
        <div class="bg-gradient-to-r from-purple-50 to-pink-50 rounded-2xl p-8 mb-8">
            <div class="flex items-center mb-6">
                <i class="fas fa-project-diagram text-3xl text-purple-600 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">算法流程图</h2>
            </div>
            <div class="mermaid">
                graph TD
                    A[开始] --> B{长度相等?}
                    B -->|否| C[返回 False]
                    B -->|是| D[初始化计数数组]
                    D --> E[遍历字符串]
                    E --> F[s中字符计数+1]
                    F --> G[t中字符计数-1]
                    G --> H{遍历完成?}
                    H -->|否| E
                    H -->|是| I{计数全为0?}
                    I -->|是| J[返回 True]
                    I -->|否| K[返回 False]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style J fill:#27c93f,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#ff5f56,stroke:#fff,stroke-width:2px,color:#fff
                    style K fill:#ff5f56,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Code Implementation -->
        <div class="mb-12">
            <div class="flex items-center mb-6">
                <i class="fas fa-code text-3xl text-green-600 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">示例代码</h2>
            </div>
            
            <div class="code-block">
                <div class="code-header">
                    <div class="code-dots">
                        <div class="dot dot-red"></div>
                        <div class="dot dot-yellow"></div>
                        <div class="dot dot-green"></div>
                    </div>
                    <span class="text-gray-400 text-sm">Python</span>
                </div>
                <pre><code><span class="keyword">def</span> <span class="function">isAnagram</span>(s, t):
    <span class="keyword">if</span> <span class="function">len</span>(s) != <span class="function">len</span>(t):
        <span class="keyword">return</span> <span class="keyword">False</span>
    
    <span class="comment"># 初始化26个字母的计数数组</span>
    counter = [<span class="number">0</span>] * <span class="number">26</span>
    
    <span class="comment"># 同时遍历两个字符串</span>
    <span class="keyword">for</span> c1, c2 <span class="keyword">in</span> <span class="function">zip</span>(s, t):
        counter[<span class="function">ord</span>(c1) <span class="operator">-</span> <span class="function">ord</span>(<span class="string">'a'</span>)] <span class="operator">+=</span> <span class="number">1</span>
        counter[<span class="function">ord</span>(c2) <span class="operator">-</span> <span class="function">ord</span>(<span class="string">'a'</span>)] <span class="operator">-=</span> <span class="number">1</span>
    
    <span class="comment"># 检查所有计数是否为0</span>
    <span class="keyword">return</span> <span class="function">all</span>(x <span class="operator">==</span> <span class="number">0</span> <span class="keyword">for</span> x <span class="keyword">in</span> counter)</code></pre>
            </div>
        </div>

        <!-- Extended Knowledge -->
        <div class="grid md:grid-cols-3 gap-6 mb-12">
            <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                <i class="fas fa-puzzle-piece text-4xl text-purple-500 mb-4"></i>
                <h3 class="text-xl font-bold text-gray-800 mb-3">相关题型</h3>
                <ul class="space-y-2 text-gray-700">
                    <li><i class="fas fa-chevron-right text-purple-400 mr-2"></i>字母异位词分组</li>
                    <li><i class="fas fa-chevron-right text-purple-400 mr-